$(function () {

  function formDate(dateStr) {
    let date = new Date(dateStr);
    return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
  }
  // 轮播图数据
  $.ajax({
    url: baseUrl + '/slides',
    type: 'get',
    success(res) {
      const newHtml = template('swiperTemplate', { swiperList: res, baseUrl })
      $('.swiper-container .swiper-wrapper').html(newHtml)
      var swiper = new Swiper('.swiper-container', {
        navigation: {
          nextEl: '.swiper-button-next',
          prevEl: '.swiper-button-prev',
        },
        pagination: {
          el: '.swiper-pagination',
        },
        autoplay: true,
        loop: true,
      });
    },
    error(err) {
      console.log(err);
    }
  })

  // 最新发布

  $.ajax({
    url: baseUrl + '/posts/lasted',
    type: 'get',
    success(res) {
      const newHtml = template('releaseTemplate', { releaseList: res, baseUrl, handleDate: formDate })
      $('.release .box').html(newHtml)
    },
    error(err) {
      console.log(err);
    }
  })

})


